package com.yupi.yupicturebackend.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yupi.yupicturebackend.api.aliyunai.model.outPainting.CreateOutPaintingTaskResponse;
import com.yupi.yupicturebackend.api.aliyunai.model.test2Image.CreateText2ImageRequest;
import com.yupi.yupicturebackend.api.aliyunai.model.test2Image.CreateText2ImageResponse;
import com.yupi.yupicturebackend.model.dto.picture.*;
import com.yupi.yupicturebackend.model.entity.Picture;
import com.yupi.yupicturebackend.model.entity.User;
import com.yupi.yupicturebackend.model.vo.PictureVO;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
* @author Administrator
* @description 针对表【picture(图片)】的数据库操作Service
* @createDate 2025-03-06 15:48:22
*/
public interface PictureService extends IService<Picture> {

    /**
     * 上传图片
     *
     * @param
     * @param pictureUploadRequest
     * @param loginUser
     * @return
     */
    PictureVO uploadPicture(Object inputSource,
                            PictureUploadRequest pictureUploadRequest,
                            User loginUser);


    QueryWrapper<Picture> getQueryWrapper(PictureQueryRequest pictureQueryRequest);

    /**
     * 从数据库获取图片信息 Picture 并转PictureVO ，然后关联user信息
     * @param picture
     * @param request
     * @return
     */
    PictureVO getPictureVO(Picture picture, HttpServletRequest request);

    Page<PictureVO> getPictureVOPage(Page<Picture> picturePage, HttpServletRequest request);

    void validPicture(Picture picture);

    /**
     * 图片审核
     *
     * @param pictureReviewRequest
     * @param loginUser
     */
    void doPictureReview(PictureReviewRequest pictureReviewRequest, User loginUser);

    boolean doAIPictureReview(List<PictureAIReviewRequest>  pictureAIReviewRequest);

    void fillReviewParams(Picture picture, User loginUser);

    /**
     * 批量抓取和创建图片
     *
     * @param pictureUploadByBatchRequest
     * @param loginUser
     * @return 成功创建的图片数
     */
    Integer uploadPictureByBatch(
            PictureUploadByBatchRequest pictureUploadByBatchRequest,
            User loginUser
    );

    @Async
    void clearPictureFile(Picture oldPicture);

    void checkPictureAuth(User loginUser, Picture picture);

    void deletePicture(long pictureId, User loginUser);

    void editPicture(PictureEditRequest pictureEditRequest, User loginUser);

    List<PictureVO> searchPictureByColor(Long spaceId, String picColor, User loginUser);

    void editPictureByBatch(PictureEditByBatchRequest pictureEditByBatchRequest, User loginUser);

    /**
     * ai扩图
     * @param createPictureOutPaintingTaskRequest
     * @param loginUser
     * @return
     */
    CreateOutPaintingTaskResponse createPictureOutPaintingTask(CreatePictureOutPaintingTaskRequest createPictureOutPaintingTaskRequest, User loginUser);

    /**
     * 创建文配图片任务
     * @param createPictureText2ImageTaskRequest
     * @return
     */
    CreateText2ImageResponse createPictureText2ImageTask(CreatePictureText2ImageTaskRequest createPictureText2ImageTaskRequest);

    /**
     * 用户对图片点赞
     */
    void likePicture(Long pictureId, User loginUser);

    /**
     * 判断用户是否对图片点赞
     * @param picture
     * @param loginUser
     */
    void isPictureLiked(Picture picture, User loginUser);


    /**
     * 根据id获取图片
     * @param id
     * @param request
     * @return
     */
    PictureVO getPictureVOById(long id, HttpServletRequest request);

//    异步执行 图像理解的描述元素到数据库
    @Async
    void savePictureElements(String url, String description, Long id);
}
